﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Threading;
using Utilities.QuickSql;
using MySql.Data;

namespace Deviseur_Cs2i_Car
{
    public partial class AdminTypeMoteur : Form
    {
        public AdminTypeMoteur()
        {
            InitializeComponent();

            Thread TypeMoteurThread = new Thread(new ThreadStart(getAllTypeMoteur_Thread));
            TypeMoteurThread.Start();
        }

        private void getAllTypeMoteur_Thread()
        {
            Invoke(new MethodInvoker(getAllTypeMoteur));
        }

        private void getAllTypeMoteur()
        {
            Table TypeMoteurVoiture = Program.Db.QueryTable("SELECT NumTypeMoteur, LibelleTypeMoteur, LibelleHTDI FROM TYPEMOTEUR LEFT OUTER JOIN HTDI ON TYPEMOTEUR.NumHTDI=HTDI.NumHTDI");

            this.dataGridView1.Rows.Clear();

            foreach (Record r in TypeMoteurVoiture)
                this.dataGridView1.Rows.Add(r.Values[0], r.Values[1], r.Values[2]);
        }

        private void AdminTypeMoteur_Activated(object sender, EventArgs e)
        {
            Thread TypeMoteurThread = new Thread(new ThreadStart(getAllTypeMoteur_Thread));
            TypeMoteurThread.Start();
        }

        private void AddTypeMoteur_Click_1(object sender, EventArgs e)
        {
            AddTypeMoteur FenAddTypeMoteur = new AddTypeMoteur();
            FenAddTypeMoteur.ShowDialog();
        }
        private void buttonDelTypeMoteur_Click_1(object sender, EventArgs e)
        {
            TYPEMOTEUR delType = new TYPEMOTEUR();
            delType.delete_TypeMoteur(Convert.ToInt32(this.dataGridView1.SelectedRows[0].Cells[0].Value.ToString()));
            Thread TypeThread = new Thread(new ThreadStart(getAllTypeMoteur_Thread));
            TypeThread.Start();
        }

        private void ModifTypeMoteur_Click(object sender, EventArgs e)
        {
            AddTypeMoteur FenAddTypeMoteur = new AddTypeMoteur(Convert.ToInt32(this.dataGridView1.SelectedRows[0].Cells[0].Value.ToString()));
            FenAddTypeMoteur.ShowDialog();
            // Coucou
        }
    }
}
